package net.maku.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import net.maku.bean.query.WebIncomeRecordQuery;
import net.maku.bean.vo.WebIncomeRecordVO;
import net.maku.convert.WebIncomeRecordConvert;
import net.maku.entity.WebIncomeRecordEntity;
import net.maku.mapper.WebIncomeRecordMapper;
import net.maku.utils.PageResult;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
 



/**
 * 返利记录表
 *
 * @author 阿沐 babamu@126.com
 * @since 1.0.0 2024-09-06
 */
@Service
@AllArgsConstructor
public class WebIncomeRecordServiceImpl extends BaseServiceImpl<WebIncomeRecordMapper, WebIncomeRecordEntity> implements IService<WebIncomeRecordEntity> {
//public class WebIncomeRecordServiceImpl extends BaseServiceImpl<WebIncomeRecordMapper, WebIncomeRecordEntity> {
 
    public PageResult<WebIncomeRecordVO> page(WebIncomeRecordQuery query) {
        IPage<WebIncomeRecordEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));

        return new PageResult<>(WebIncomeRecordConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
    }

    private LambdaQueryWrapper<WebIncomeRecordEntity> getWrapper(WebIncomeRecordQuery query){
        LambdaQueryWrapper<WebIncomeRecordEntity> wrapper = Wrappers.lambdaQuery();
        return wrapper;
    }
 
    public void save(WebIncomeRecordVO vo) {
        WebIncomeRecordEntity entity = WebIncomeRecordConvert.INSTANCE.convert(vo);

        baseMapper.insert(entity);
    }
 
    public void update(WebIncomeRecordVO vo) {
        WebIncomeRecordEntity entity = WebIncomeRecordConvert.INSTANCE.convert(vo);

        updateById(entity);
    }
 
    @Transactional(rollbackFor = Exception.class)
    public void delete(List<Long> idList) {
        removeByIds(idList);
    }

}